const {
  http
} = require("../../../../utils/apiutils")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    pageNo: 1,
    total: 0,
    rzInfo: {},
    show: false,
  },
  onClose: function () {
    this.setData({
      show: false,
    })
  },

  onclickCall: function (e) {

    // let item = e.currentTarget.dataset.item;
    wx.makePhoneCall({
      phoneNumber: this.data.rzInfo.contactPhone,
    })
    // var data = {
    //   "pageNo": this.data.pageNo, //手机号码
    //   "pageSize": "10" //密码
    // }
    // var that = this;
    // wx.showLoading({
    //   title: '加载中...',
    // })
    // http.gethire(data,
    //   function (res) {
    //     wx.hideLoading()
    //     console.log("------报名岗位列表---", res);
    //     if (res.code == 0) {
    //       var pageNo = res.data.current;
    //       var total = res.data.pages;
    //       var arr = res.data.records;
    //       if (pageNo ==1) {
    //         that.setData({
    //           dataList: arr,
    //           pageNo,
    //           total
    //         })

    //       } else if (pageNo <= total) {

    //         that.setData({
    //           dataList: [...that.data.dataList, ...arr],
    //           pageNo,
    //           total
    //         })
    //       }
    //     } else {
    //       wx.showToast({
    //         title: res.message,
    //         icon: "none",
    //       })
    //     }
    //   },
    //   function (err) {
    //     wx.hideLoading()
    //   })

  },

  onclickCall1: function (e) {

    let item = e.currentTarget.dataset.item;

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.entryInfo(item.jobId,
      function (res) {
        wx.hideLoading()
        console.log("------报名岗位列表---", res);
        if (res.code == 0) {
          that.setData({
            rzInfo: res.data,
            show: true,
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.gethire();

  },

  onclickCall2: function (e) {
    let item = e.currentTarget.dataset.item;
    // console.log("-------到岗打卡-----",item);
    // this.clockIn(item.id);
    let data = {
      id: item.id,
      name: item.jobName,
      workplace: item.workplace,
      type: 1,
      jobId: item.jobId,
      interviewDate:item.interviewDate,
    }
    wx.navigateTo({
      url: '/pages/clockin/clockin?data=' + encodeURIComponent(JSON.stringify(data)),
    })

  },
  onclickCall3: function () {
    let item = e.currentTarget.dataset.item;
    console.log("-----------", item);
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.registrationD(item.id,
      function (res) {
        wx.hideLoading()
        that.getregistration();
        if (res.code == 0) {
          wx.showToast({
            title: "取消成功",
            icon: "none",
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })


  },
  onclickCall3: function () {
    wx.openLocation({
      latitude: Number(this.data.rzInfo.lat),
      longitude: Number(this.data.rzInfo.lng),
      name: this.data.rzInfo.workPlace,
      address: this.data.rzInfo.workPlace,
    })

  },
  gethire: function () {
    var data = {
      "pageNo": this.data.pageNo, //手机号码
      "pageSize": "10" //密码
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.gethire(data,
      function (res) {
        wx.hideLoading()
        console.log("------报名岗位列表---", res);
        if (res.code == 0) {
          var pageNo = res.data.current;
          var total = res.data.pages;
          var arr = res.data.records;
          if (pageNo == 1) {
            that.setData({
              dataList: arr,
              pageNo,
              total
            })

          } else if (pageNo <= total) {

            that.setData({
              dataList: [...that.data.dataList, ...arr],
              pageNo,
              total
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})